package com.view;


import java.io.OutputStream;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts2.ServletActionContext;
import com.controller.ControladorPartitura;
import com.model.Imagen;
import com.opensymphony.xwork2.ActionSupport;

public class ImagenAction extends ActionSupport{
	private static final long serialVersionUID = 1L;
	private String idImagen;
	private Imagen imagen;
	private ControladorPartitura linkController;
	
	public ImagenAction(){
		setLinkController(new ControladorPartitura());
	}
	
	public String execute(){
		return SUCCESS;
	}
	
	public String Imagenes(){
		try {
			imagen = linkController.listaImagenes(Integer.parseInt(getIdImagen()));
			byte[] imagen2 = imagen.getImagen();
            HttpServletResponse response = ServletActionContext.getResponse();  
            response.setContentType("image/png");  
            OutputStream out = response.getOutputStream();  
            out.write(imagen2); 
		} catch (Exception e) {
			e.printStackTrace();
		}
		return NONE;
	}
	public ControladorPartitura getLinkController() {
		return linkController;
	}

	public void setLinkController(ControladorPartitura linkController) {
		this.linkController = linkController;
	}

	public String getIdImagen() {
		return idImagen;
	}

	public void setIdImagen(String idImagen) {
		this.idImagen = idImagen;
	}
}
